package com.bytecodezz.app.base.extend.ui

import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import com.bytecodezz.app.base.extend.R

/** 扩展方法**/
fun FragmentActivity.toast(message: String, duration: Int? = null) {
    val toastView: View =
        LayoutInflater.from(this).inflate(R.layout.extend_toast_default_layout, null)
    val toastTv: TextView = toastView.findViewById(R.id.extend_toast_content_tv)
    toastTv.text = message
    val toast = Toast(this)
    toast.setGravity(Gravity.CENTER, 0, 0)
    toast.duration = Toast.LENGTH_SHORT;
    toast.view = toastView;
    toast.show()
}

/** 扩展方法**/
fun Fragment.toast(message: String, duration: Int? = null) {
    activity?.run {
        val toastView: View =
            LayoutInflater.from(this).inflate(R.layout.extend_toast_default_layout, null)
        val toastTv: TextView = toastView.findViewById(R.id.extend_toast_content_tv)
        toastTv.text = message
        val toast = Toast(this)
        toast.setGravity(Gravity.CENTER, 0, 0)
        toast.duration = Toast.LENGTH_SHORT;
        toast.view = toastView;
        toast.show()
    }
}